<template>
    <div style="height:100%;width:100%;position:relative;">
        <div class="pagetop">
            <div class="top-content" style="min-width: 945px;">
                <div class="row-content">
                    <span class="row-title first-title">报告单元</span>
                    <span class="search-param__text">
                        <rm-ddl-rptunit prgno="LIS445" defaultflag="1" reporttype="bact" v-model="searchParam.rptunitid" width="210px" @change="rptunitChange"></rm-ddl-rptunit>
                    </span>
                    <span class="row-title">病人号</span>
                    <span class="search-param__text">
                        <el-input ref="changeref2" v-model="searchParam.pat_no" placeholder="病历号" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">病人来源</span>
                    <span class="search-param__text">
                        <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人来源" v-model="searchParam.pat_typecode" width="105px" @change="pattypeChange"></rm-ddl-common>
                    </span>
                    <span class="row-title">床号</span>
                    <span class="search-param__text">
                        <el-input ref="changeref9" v-model="searchParam.req_bedno" placeholder="床号" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">病人ID</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.pat_id" style="width: 105px;"></el-input>
                    </span>
                </div>
                <div class="row-content">
                    <span class="row-title first-title search-time">
                        <el-select v-model="searchParam.datekind" placeholder="请选择">
                            <el-option v-for="item in dataOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </span>
                    <span class="search-param__text">
                        <el-date-picker class="top-datepicker" v-model="searchParam.startdate" type="date" placeholder="开始日期" :picker-options="samplePickerOptions" value-format="yyyy-MM-dd" style="width:95px">
                        </el-date-picker> 至
                        <el-date-picker class="top-datepicker" v-model="searchParam.enddate" type="date" placeholder="结束日期" :picker-options="samplePickerOptions" value-format="yyyy-MM-dd" style="width:96px">
                        </el-date-picker>
                    </span>
                    <span class="row-title">姓名</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.pat_name" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">病人病区</span>
                    <span class="search-param__text">
                        <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="searchParam.req_wardno" clearable width="105px" @change="reqwardChange"></rm-ddl-common>
                    </span>
                    <span class="row-title">病区组</span>
                    <span class="search-param__text">
                        <el-select v-model="searchParam.wardcombno" placeholder="请选择" clearable style="width:105px">
                            <el-option v-for="(item,index) in wordList" :key="index + item.combno" :value="item.combno" :label="item.combname"></el-option>
                        </el-select>
                    </span>
                    <span class="row-title">急诊标志</span>
                    <span class="search-param__text">
                        <el-select v-model="searchParam.emer_flag" style="width:105px">
                            <el-option v-for="(item,index) in emerOptions" :key="index" :value="item.value" :label="item.label"></el-option>
                        </el-select>
                    </span>
                </div>
                <div class="row-content">
                    <span class="row-title first-title">药敏标志</span>
                    <span class="search-param__text radio-content">
                        <el-radio-group v-model="searchParam.medtype" style="width: 210px;">
                            <el-radio :label="1">有药敏</el-radio>
                            <el-radio :label="2">无药敏</el-radio>
                            <el-radio :label="0">全部</el-radio>
                        </el-radio-group>
                    </span>
                    <span class="row-title">样本号</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.sampleno" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">申请科室</span>
                    <span class="search-param__text">
                        <!-- <rm-pop-common datatype="dept" dataname="科室" v-model="searchParam.req_deptno" size="mini" width="105px"></rm-pop-common> -->
                        <el-input v-model="searchParam.req_deptno" @input="inputChange($event, 'req_deptno')" @dblclick.native="openMultiplepop('req_deptno')" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">送检目的</span>
                    <span class="search-param__text">
                        <!-- <rm-ddl-common datatype="bactpurpose" dataname="检验目的" v-model="searchParam.purposeno" @change="purposeChange" width="105px"></rm-ddl-common> -->
                        <!-- <el-autocomplete :popper-append-to-body="true" v-model="searchParam.req_reason" :fetch-suggestions="querySearchpurpose" @select="purposeChange($event)" popper-class="mini-select select-box" style="width:105px;">
                            <template slot-scope="{ item }">
                                <div class="name" style="width: 150px;">{{ item.purposename }}</div>
                            </template>
                        </el-autocomplete> -->
                        <el-input v-model="searchParam.req_reason" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">专家评语</span>
                    <span class="search-param__text">
                        <!-- <el-select v-model="rechkflag" placeholder="请选择" clearable style="width:105px">
                            <el-option v-for="(item,index) in germcommentList" :key="index + item.germcommentid" :value="item.germcommentname" :label="item.germcommentname"></el-option>
                        </el-select> -->
                        <el-autocomplete :popper-append-to-body="true" v-model="searchParam.germcommentname" :fetch-suggestions="querySearchgermcomment" placeholder="" @select="germcommentChange($event)" popper-class="mini-select select-box" style="width:105px;">
                            <template slot-scope="{ item }">
                                <div class="name" style="width: 150px;">{{ item.germcommentname }}</div>
                            </template>
                        </el-autocomplete>
                    </span>
                </div>
                <div class="row-content">
                    <span class="row-title first-title">报告项目</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.rptitemval" @input="inputChange($event, 'rptitemval')" @dblclick.native="dialogRptVisible = true;" style="width: 210px;"></el-input>
                        <!-- <rm-ddl-rptitem prgno="LIS445" :germmode="false" v-model="searchParam.rptitemval" width="210px"></rm-ddl-rptitem> -->
                    </span>
                    <span class="row-title title-content">条码号</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.barcode" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">申请医生</span>
                    <span class="search-param__text">
                        <rm-ddl-common datatype="doctor" dataname="医生" v-model="searchParam.req_docno" width="105px" @change="reqdocChange"></rm-ddl-common>
                    </span>
                    <span class="row-title">标本类型</span>
                    <span class="search-param__text">
                        <!-- <rm-ddl-common datatype="specimen" dataname="标本类型" v-model="searchParam.specimen_code" size="mini" width="105px"></rm-ddl-common> -->
                        <el-input v-model="searchParam.specimen_code" @input="inputChange($event, 'specimen_code')" @dblclick.native="openMultiplepop('specimen_code')" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">项目组合</span>
                    <span class="search-param__text">
                        <rm-ddl-common datatype="reportitemcomb" dataname="项目组合" v-model="searchParam.sel_itemcombid" width="105px" @change="itemcombChange"></rm-ddl-common>
                    </span>
                </div>
                <div class="row-content">
                    <span class="row-title first-title">药敏条件</span>
                    <span>
                        <!-- <el-input v-model="searchParam.labqueryresultmed" @change="labqueryresultChange" style="width: 158px;"></el-input> -->
                        <el-select v-model="searchParam.labqueryresultmed" @change="labqueryresultChange" clearable style="width: 158px;">
                            <el-option v-for="(item,index) in medcombOption" :value="item.data" :label="item.display" :key="index"></el-option>
                        </el-select>
                        <el-button class="el-button--310 search-button" @click="conditionPop(2)">自定义</el-button>
                    </span>
                    <span class="row-title">临床诊断</span>
                    <span class="search-param__text">
                        <el-input v-model="searchParam.pat_diag" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">耐药机制</span>
                    <span class="search-param__text">
                        <!-- <rm-ddl-common ref="ddlrescode" datatype="resdict" dataname="耐药机制" v-model="searchParam.resistrules" :clearable="true" :showcode="true" pclass="mini-select" width="105px"></rm-ddl-common> -->
                        <el-input v-model="searchParam.resistrules" @input="inputChange($event, 'resistrules')" @dblclick.native="openMultiplepop('resistrules')" style="width: 105px;"></el-input>
                    </span>
                    <span class="row-title">送检医院</span>
                    <span class="search-param__text">
                        <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchParam.hospcode" width="105px" @change="hospChange"></rm-ddl-common>
                    </span>
                    <span class="row-title">标本备注</span>
                    <span class="search-param__text">
                        <el-autocomplete ref="specimencommref" class="inline-input" v-model="searchParam.specimen_comm" style="width:105px" :fetch-suggestions="filterDcspecimencomm" placeholder="备注" @select="changeDcspecimencomm">
                            <template slot-scope="{ item }">
                                <div class="name">{{ item.comm_name }}</div>
                            </template>
                        </el-autocomplete>
                    </span>
                </div>
                <div class="row-content">
                    <span class="row-title first-title">多项目条件</span>
                    <span class="search-param__text">
                        <!-- <el-input v-model="searchParam.resultcomb" style="width: 158px;"></el-input> -->
                        <el-select v-model="searchParam.labqueryresult" @change="labqueryresultChange" clearable style="width: 158px;">
                            <el-option v-for="(item,index) in resultcombOption" :value="item.data" :label="item.display" :key="index"></el-option>
                        </el-select>
                        <el-button class="el-button--310 search-button" @click="conditionPop(1)">自定义</el-button>
                    </span>
                    <span class="search-param__text">
                        <el-checkbox-group v-model="searchParam.germflag" style="width: 295px;margin-left: 17px;">
                            <el-checkbox label="1">阴性结果</el-checkbox>
                            <el-checkbox label="2">阳性菌</el-checkbox>
                            <el-checkbox label="3">正常菌种</el-checkbox>
                            <el-checkbox label="4">涂片结果</el-checkbox>
                        </el-checkbox-group>
                    </span>
                    <span class="search-param__text radio-content" style="border: solid 1px #cccccc;">
                        <el-radio-group v-model="searchParam.rechkflag" style="width: 170px;margin-left: 5px;">
                            <el-radio :label="0">全部</el-radio>
                            <el-radio :label="1">已审核</el-radio>
                            <el-radio :label="2">未审核</el-radio>
                        </el-radio-group>
                    </span>
                    <!-- <span class="search-param__text" style="margin-left: 10px;">
                        <el-checkbox v-model="searchParam.barcodeflag">剔除复制标本</el-checkbox>
                    </span> -->
                    <span class="row-title">致病菌数</span>
                    <span class="search-param__text">
                        <!-- <rm-ddl-common ref="ddlrescode" datatype="resdict" dataname="耐药机制" v-model="searchParam.resistrules" :clearable="true" :showcode="true" pclass="mini-select" width="105px"></rm-ddl-common> -->
                        <el-input v-model="searchParam.evalcount" style="width: 105px;"></el-input>
                    </span>
                </div>
                <div class="row-content">
                    <div class="top-deal">
                        <el-button icon="el-icon-search" @click="queryData" type="primary">查询</el-button>
                        <el-button icon="el-icon-close" @click="clearAllData">清除</el-button>
                        <el-button icon="el-icon-download" @click="exportExcel" :disabled="!changeflag">导出</el-button>
                        <el-button @click="setExportColumn">导出列设置</el-button>
                        <el-button icon="el-icon-printer" @click="btnPrint" :disabled="!changeflag">打印</el-button>
                        <el-button icon="el-icon-edit-outline" @click.native="RptStyleSetting" :disabled="!changeflag">打印样式设计</el-button>
                    </div>
                </div>
            </div>
        </div>
        <div class="pagecenter">
            <rm-layout-right splitcolor="#FFFFFF" movingcolor="#CCFFFF" :splitwidth=5 :fixsize=384>
                <div class="middle-left" style="height:100%">
                    <vxe-table ref="xTable" :data.sync="sampleList" :loading="sampleLoading" height="auto" border size="mini" 
                        show-overflow show-header-overflow highlight-current-row resizable stripe header-align="center" 
                        :sort-config="{trigger: 'cell'}" show-footer @current-change="currentChangeEvent"
                        :footer-method="footerMethod" :footer-cell-class-name="footerCellClassName" :row-class-name="rowClassName">
                        <!-- <vxe-table-column type="index" title=" " width="40" align="center"></vxe-table-column> -->
                        <vxe-table-column field="rechkstate" sortable title="状态" width="60" align="center"></vxe-table-column>
                        <vxe-table-column field="rptunitname" title="报告单元" width="90" sortable></vxe-table-column>
                        <vxe-table-column field="sampledate" title="标本日期" width="80" sortable :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="sampleno" title="标本编号" width="80" sortable></vxe-table-column>
                        <vxe-table-column field="pat_name" sortable title="病人姓名" width="80" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_no" sortable title="病人号" width="80"></vxe-table-column>
                        <vxe-table-column field="pat_sexname" sortable title="性别" width="40" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_agestr" sortable title="年龄" width="50"></vxe-table-column>
                        <vxe-table-column field="specimen_name" sortable title="标本类型" width="100"></vxe-table-column>
                        <vxe-table-column field="rpt_itemcode" title="项目代码" width="80" sortable></vxe-table-column>
                        <vxe-table-column field="rpt_itemname" title="培养结果/检验项目" width="250" sortable></vxe-table-column>
                        <vxe-table-column field="result_str" title="检验结果" width="70" sortable></vxe-table-column>
                        <vxe-table-column field="result1" title="菌落计数" width="120" sortable></vxe-table-column>
                        <vxe-table-column field="result4" title="耐药机制" width="60" sortable></vxe-table-column>
                        <vxe-table-column field="req_deptname" sortable title="申请科室" width="100"></vxe-table-column>
                        <vxe-table-column field="req_bedno" sortable title="床号" width="70"></vxe-table-column>
                        <vxe-table-column field="barcode" sortable title="条码号" width="100"></vxe-table-column>
                        <vxe-table-column field="rechk_dt" sortable title="审核时间" width="120"></vxe-table-column>
                        <vxe-table-column field="rechk_username" sortable title="审核医生" width="70" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_typecodename" sortable title="病人类型" align="center" width="80"></vxe-table-column>
                        <vxe-table-column field="req_wardname" title="病人病区" width="100" sortable></vxe-table-column>
                        <vxe-table-column field="result_txt" title="专家评语" width="90" align="center" sortable></vxe-table-column>
                        <!-- 药敏组 -->
                        <vxe-table-column field="emer_flag" title="加急" width="40" align="center" sortable>
                            <template v-slot="{row}">
                                <div style="color:red">{{row.emer_flag=="0"?"":"急"}}</div>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="redo_flagname" title="复查标志" width="60" align="center" sortable></vxe-table-column>
                        <vxe-table-column field="print_count" title="打印次数" width="60" align="right" sortable></vxe-table-column>
                        <vxe-table-column field="chargetypename" title="收费类别" width="90" align="center" sortable></vxe-table-column>
                        <vxe-table-column field="pat_diag" sortable title="临床诊断" width="160"></vxe-table-column>
                        <vxe-table-column field="req_dt" sortable title="申请时间" width="120"></vxe-table-column>
                        <vxe-table-column field="req_docname" sortable title="申请医生" width="70" align="center"></vxe-table-column>
                        <vxe-table-column field="sampled_dt" sortable title="采样时间" width="120"></vxe-table-column>
                        <vxe-table-column field="recieve_dt" sortable title="接收时间" width="120"></vxe-table-column>
                        <vxe-table-column field="input_dt" sortable title="录入时间" width="120"></vxe-table-column>
                        <vxe-table-column field="test_info" title="上机信息" width="70" sortable></vxe-table-column>
                        <vxe-table-column field="test_dt" title="上机时间" width="140" align="center" sortable></vxe-table-column>
                        <vxe-table-column field="report_username" title="检验医生" width="70" align="center" sortable></vxe-table-column>
                        <vxe-table-column field="report_comm" title="报告单备注" width="100" sortable></vxe-table-column>
                        <vxe-table-column field="lab_advice" title="实验室意见" width="140" sortable></vxe-table-column>
                        <!-- 项目数 -->
                        <!-- <vxe-table-column field="instr_advice" title="仪器辅助诊断" width="150" sortable></vxe-table-column>
                        <vxe-table-column field="rechk2_dt" title="二审时间" width="140" sortable></vxe-table-column>
                        <vxe-table-column field="rechk2_user" title="二审医生" width="70" sortable></vxe-table-column>
                        <vxe-table-column field="lastprint_dt" title="最后打印时间" width="140" sortable></vxe-table-column> -->
                        <!-- <vxe-table-column field="" title="计价" width="140" sortable></vxe-table-column> -->
                        <!-- <vxe-table-column field="prereport_dt" title="预计报告时间" width="140" sortable></vxe-table-column> -->
                        <vxe-table-column field="reportid" title="报告ID" width="160" sortable></vxe-table-column>
                        <vxe-table-column field="hospname" title="送检医院" width="180" sortable></vxe-table-column>
                        <vxe-table-column field="sample_detail" title="标本状态备注" width="140" sortable></vxe-table-column>
                        <!-- <vxe-table-column field="reportid" title="申请单ID" width="100" sortable></vxe-table-column> -->
                        <vxe-table-column field="pat_cardno" title="就诊卡号" width="110" sortable></vxe-table-column>
                        <vxe-table-column field="inp_id" title="就诊号" width="60" sortable></vxe-table-column>
                        <vxe-table-column field="inp_date" title="入院日期" width="140" sortable></vxe-table-column>
                        <vxe-table-column field="pat_phone" title="联系电话" width="100" sortable></vxe-table-column>
                        <vxe-table-column field="pat_id" title="病人ID" width="130" sortable></vxe-table-column>
                        <vxe-table-column field="last_dt" title="最后修改时间" width="120" sortable></vxe-table-column>
                        <vxe-table-column field="release_dt" title="发布时间" width="140" sortable></vxe-table-column>
                        <vxe-table-column field="release_username" title="发布人" width="70" align="right" sortable></vxe-table-column>
                        <vxe-table-column field="req_reason" title="送检目的" width="120"></vxe-table-column>
                        <!-- <vxe-table-column field="is_changed" title="是否修改" width="70" sortable></vxe-table-column>
                        <vxe-table-column field="changed_afterreport" title="打印、审核后修改" width="130" sortable></vxe-table-column>
                        <vxe-table-column field="unprint_flag" title="禁止打印标志" width="100" sortable></vxe-table-column>
                        <vxe-table-column field="unprint_reason" title="禁止打印原因" width="100" sortable></vxe-table-column> -->
                        <vxe-table-column field="pat_idcardno" title="身份证/护照号" width="200" sortable></vxe-table-column>
                        <vxe-table-column field="pat_diag_icd" title="临床诊断标准码" width="160" sortable></vxe-table-column>
                        <vxe-table-column field="specimen_code" title="标本类型代码" width="100" sortable></vxe-table-column>
                    </vxe-table>
                </div>
                <template v-slot:fix>
                    <div class="middle-right" style="height:100%;">
                        <vxe-table ref="medTable" :data.sync="medList" :loading="medLoading" height="auto" width="100%" border size="mini" 
                            resizable stripe show-header-overflow show-overflow header-align="center" highlight-current-row>
                            <vxe-table-column field="medname" sortable title="抗生素" width="160"></vxe-table-column>
                            <vxe-table-column field="medresult" sortable title="结果" width="60" align="center">
                                <template v-slot="{ row }">
                                    <div :style="ResultClassGerm(row)">
                                        <span>{{row.medresult}}</span>
                                    </div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="rad" sortable title="rad" width="50" align="center"></vxe-table-column>
                            <vxe-table-column field="mic" sortable title="mic" width="50" align="center"></vxe-table-column>
                            <vxe-table-column field="result_flag" sortable title="结果标识" width="80" align="center"></vxe-table-column>
                            <vxe-table-column field="result6" sortable title="参考范围" width="100" align="center"></vxe-table-column>
                            <vxe-table-column field="appmethod" sortable title="试验方法" width="65"></vxe-table-column>
                            <vxe-table-column field="medconc" sortable title="药物浓度" width="60"></vxe-table-column>
                            <vxe-table-column field="medgroup" sortable title="药敏分组" width="60"></vxe-table-column>
                            <vxe-table-column field="guidelines" sortable title="使用标准" width="65"></vxe-table-column>
                            <vxe-table-column field="instrname" sortable title="检验仪器" width="150" align="center"></vxe-table-column>
                        </vxe-table>
                    </div>
                </template>
            </rm-layout-right>
        </div>

        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="popcommonVisible" ref="popcommondialog">
            <!-- <rm-pop-common v-if="popdatatype != 'pat_typecode' && popdatatype != 'req_deptno' && popdatatype != 'pat_sex' && popdatatype != 'req_wardno'" :datatype="popdatatype" @cancel="popcommonVisible=false()" @change="popchange" ref="popcommon"></rm-pop-common> -->
            <!-- <rm-pop-common v-show="popdatatype == 'pat_typecode'" datatype="seccode" kindno="PT" dataname="病人类型" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common>
            <rm-pop-common v-show="popdatatype == 'pat_sex'" datatype="seccode" kindno="SX" dataname="性别" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common> -->
            <rm-pop-common v-show="popdatatype == 'req_deptno'" datatype="dept" dataname="申请科室" :multiple="multiplepopcommon" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common>
            <!-- <rm-pop-common v-show="popdatatype == 'req_wardno'" datatype="ward" dataname="病区" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common>
            <rm-pop-common v-show="popdatatype == 'req_docno'" datatype="doctor" dataname="医生" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common> -->
            <rm-pop-common v-show="popdatatype == 'specimen_code'" datatype="specimen" dataname="标本类型" :multiple="multiplepopcommon" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common>
            <!-- <rm-pop-common v-show="popdatatype == 'purposeno'" datatype="bactpurpose" dataname="检验目的" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common> -->
            <rm-pop-common v-show="popdatatype == 'resistrules'" datatype="resdict" dataname="耐药机制" :multiple="multiplepopcommon" @cancel="popcommonVisible=false" @change="popchange" ref="popcommon"></rm-pop-common>
        </el-dialog>
        <!-- 报告项目多选 -->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogRptVisible" :destroy-on-close="true" title="报告项目" v-if="dialogRptVisible">
            <rm-chkboxSelect2 prgno="LIS445" @cancel="dialogRptVisible=false" :isAllRpt="1" :rptunitid="searchParam.rptunitid" :rptunitdisabled="true" @selitem="addrptitem" @selitems="selectRptItems" ref="rptdialog"></rm-chkboxSelect2>
        </el-dialog>
        <!-- 自定义 -->
        <el-dialog width="830px" height="600px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="结果组合查询条件" :visible.sync="customcondVisible" v-if="customcondVisible" :destroy-on-close="true">
            <rm-customcond prono="LIS445" :rptunitid="searchParam.rptunitid" :condData="fcondData" :condtype="condtype" @refreshLaboption="refreshLaboption"></rm-customcond>
        </el-dialog>
        <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false">
            <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn"></rm-excolsetting>
        </el-dialog>
        <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
    </div>
</template>

<script>
import XEUtils from "xe-utils"; //引入工具类
import excelExport from "@/components/common/excelexport"; 
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
import RmCustomcond from '../../../rmcompents/rmcustom/rm_customcond.vue';
import pubMedresult from "@/components/common/medresult";
export default {
    name: "LIS445",
    components: { 
        RmCustomcond, 
        RmExcolsetting, 
    },
    data() {
        var self = this;
        return {
            Options: {}, // 药敏结果颜色
            //medresultList: pubMedresult.medresultList,
            medresultList:[],
            userno: this.$tool.getSession(this.$tool.loginuserno),
            culturerptstyle: "5080",
            dataOptions: [
                {
                    value: "1",
                    label: "标本日期"
                },
                {
                    value: "2",
                    label: "审核日期"
                },
            ],
            germcommentList: [],
            purposeList: [],
            wordList: [],
            emerOptions: [{ label: "常规", value: "0" }, { label: "急诊", value: "1" }],
            resultcombOption: [], // 多项目条件  LIS156 结果组合查询条件
            medcombOption: [], // 药敏组合条件
            dcspecimencommList: [],
            searchParam: {
                datekind: "1",
                startdate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                enddate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                qstat: "A",
                rptunitid: 0,
                germflag: [],
                medtype: 0,
                rechkflag: 0,

            },
            fcondData: [], // 药敏自定义数据
            medcondData: [], // 药敏自定义数据
            resultcondData: [], // 多项目自定义数据
            changeflag: false,
            samplePickerOptions: {
                // disabledDate(time) {
                //     return time.getTime() > Date.now();
                // },
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                        self.startdate = new Date();
                        self.enddate = new Date();
                    }
                }]
            },
            customcondVisible: false,
            condtype: 1, // 1 为多项目自定义数据， 2 为药敏自定义数据
            popcommonVisible: false,
            popdatatype: "",
            multiplepopcommon: true,
            dialogRptVisible: false,
            sampleList: [],
            sampleLoading: false,
            medList: [],
            medLoading: false,
            excolPro: "lis445",
            chooseColumndialogVisible: false,
            allTableCol: [],
            req_deptnoname: "",
            specimen_codename: "",
            resistrulesname: "",
            rptitemname: "",
            rptunitname: "",
            pattypename: "",
            reqwardname: "",
            itemcombname: "",
            hospname: "",
            reqdocname: "",
        }
    },
    mounted() {
        this.initData();
        this.getMedResultList();
		this.$refs.excolset.colSettingToDB();
    },
    methods: {
        initData() {
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS445",
                    method: "post",
                    data: {
                        action: "initpage",
                    }
                })
                .then(response => {
                    this.germcommentList = response.germcommentlist;
                    this.dcspecimencommList = response.specimencommlist;
                    this.purposeList = response.purposelist;
                    this.Options = response.opts;
                    this.wordList = response.wordlist;
                    this.resultcombOption = response.resultcombOption;
                    this.medcombOption = response.medcombOption;
                    // this.queryData();
                })
                .catch(e => {});
        },
        queryData() {
            this.sampleLoading = true;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS445",
                    method: "post",
                    data: {
                        action: "querydata",
                        ...this.searchParam,
                        meddata: this.medcondData, // 药敏条件
                        resultdata: this.resultcondData, // 多项目条件
                        germflagstr: this.searchParam.germflag.join(","),
                    }
                })
                .then(response => {
                    this.sampleLoading = false;
                    this.sampleList = response.data;
                    if (this.sampleList.length > 0) {
                        this.changeflag = true;
                        this.$refs.xTable.setCurrentRow(this.sampleList[0]).then(row => {
                            this.queryMed(this.sampleList[0].reportid, this.sampleList[0].rpt_itemcode);
                        })
                    } else {
                        this.medList = [];
                    }
                })
                .catch(e => {
                    this.sampleLoading = false;
                    this.sampleList = [];
                    this.changeflag = false;
                });
        },
        getMedResultList(){
            this.$ddldata.getMedResultList().then((data) =>{
                this.medresultList=data;
            })
        },
        queryMed(reportid, rpt_itemcode) {
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS445",
                    method: "post",
                    data: {
                        action: "querymed",
                        reportid: reportid,
                        rpt_itemcode: rpt_itemcode, 
                    }
                })
                .then(response => {
                    this.medLoading = false;
                    this.medList = response.med.Data;
                })
                .catch(e => {
                    this.medLoading = false;
                    this.medList = [];
                });

        },
        clearAllData() {
            this.sampleList = [];
            this.changeflag = false;
            this.medList = [];
            this.searchParam = {
                datekind: "1",
                startdate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                enddate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
                qstat: "A",
                rptunitid: 0,
                germflag: [],
                medtype: 0,
                rechkflag: 0,
            };
        },
        rptunitChange(code, name) {
            this.searchParam.rptunitid = code;
            this.rptunitname = name;
        },
        pattypeChange(code, name) {
            this.searchParam.pat_typecode = code;
            this.pattypename = name;
        },
        reqwardChange(code, name) {
            this.req_wardno = code;
            this.reqwardname = name;
        },
        itemcombChange(code, name) {
            this.searchParam.sel_itemcombid = code;
            this.itemcombname = name;
        },
        hospChange(code, name) {
            this.searchParam.hospcode = code;
            this.hospname = name;
        },
        reqdocChange(code, name) {
            this.searchParam.req_docno = code;
            this.reqdocname = name;
        },
        exportExcel() {
            // let tableColumn = this.$refs.xTable.getColumns();
            // let extableColumn = [];
            // tableColumn.forEach((item) => {
            //     extableColumn.push({ title: item.title, field: item.property });
            // });
            // this.$pub.exportTableExcel(this.sampleList, extableColumn, "LIS445 细菌结果查询清单.xlsx");
            var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
            let column = this.$refs.xTable.getTableColumn().tableColumn;
            var exportColumn = [];
            if (rightlocalStorage && rightlocalStorage.length > 0) {
                let columnArr = [];
                rightlocalStorage.forEach(item => {
                    columnArr.push({
                        title: item.extitle ? item.extitle : item.title,
                        property: item.property
                    });
                });
                exportColumn = columnArr;
            } else {
                exportColumn = this.$pub.InitColumn(column);
            }
            let filtertxt = this.getExportFilter();
            let data = excelExport.getExportData(this, "sampleList", exportColumn);
            this.$pub.exportTableExcelWithData(data, exportColumn.length, "LIS445细菌结果查询.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = this.dataOptions.find((item) =>this.searchParam.datekind == item.value).label + ":" + XEUtils.toDateString(this.searchParam.startdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchParam.enddate, "yyyy-MM-dd") + "; ";
            if(this.searchParam.rptunitid) filtertxt += "报告单元:" + this.rptunitname + "; ";
            if(this.searchParam.pat_no) filtertxt += "病人号:" + this.searchParam.pat_no + "; ";
            if(this.searchParam.pat_typecode) filtertxt += "病人来源:" + this.pattypename + "; ";
            if(this.searchParam.req_bedno) filtertxt += "床号:" + this.searchParam.req_bedno + "; ";
            if(this.searchParam.pat_id) filtertxt += "病人ID:" + this.searchParam.pat_id + "; ";
            if(this.searchParam.pat_name) filtertxt += "姓名:" + this.searchParam.pat_name + "; ";
            if(this.searchParam.req_wardno) filtertxt += "病人病区:" + this.reqwardname + "; ";
            if(this.searchParam.wardcombno) filtertxt += "病区组:" + this.getOptionName(this.wordList.filter((item) =>  this.searchParam.wardcombno == item.combno)) + "; ";
            if(this.searchParam.emer_flag) filtertxt += "急诊标志:" + this.getOptionName(this.emerOptions.filter((item) =>  this.searchParam.emer_flag == item.value)) + "; ";
            if(this.searchParam.medtype) filtertxt += "药敏标志:" + (this.searchParam.medtype == 1 ? "有药敏" : this.searchParam.medtype == 2 ? "无药敏" : "全部") + "; ";
            if(this.searchParam.sampleno) filtertxt += "样本号:" + this.searchParam.sampleno + "; ";
            if(this.searchParam.req_deptno) filtertxt += "申请科室:" + this.req_deptnoname + "; ";
            if(this.searchParam.reqreason) filtertxt += "送检目的:" + this.searchParam.reqreason + "; ";
            if(this.searchParam.germcommentname) filtertxt += "专家评语:" + this.searchParam.germcommentname + "; ";
            if(this.searchParam.rptitemval) filtertxt += "报告项目:" + this.rptitemname + "; ";
            if(this.searchParam.barcode) filtertxt += "条码号:" + this.searchParam.barcode + "; ";
            if(this.searchParam.reqdocno) filtertxt += "申请医生:" + this.reqdocname + "; ";
            if(this.searchParam.specimen_code) filtertxt += "标本类型:" + this.specimen_codename+ "; ";
            if(this.searchParam.sel_itemcombid) filtertxt += "项目组合:" + this.itemcombname + "; ";
            if(this.searchParam.labqueryresultmed) filtertxt += "药敏条件:" + this.getOptionName(this.medcombOption.filter((item) =>  this.searchParam.labqueryresultmed == item.data)) + "; ";
            if(this.searchParam.pat_diag) filtertxt += "临床诊断:" + this.searchParam.pat_diag + "; ";
            if(this.searchParam.resistrules) filtertxt += "耐药机制:" + this.resistrulesname+ "; ";
            if(this.searchParam.hoscode) filtertxt += "送检医院:" + this.hosname + "; ";
            if(this.searchParam.specimen_comm) filtertxt += "标本备注:" + this.searchParam.specimen_comm + "; ";
            if(this.searchParam.labqueryresult) filtertxt += "多项目条件:" + this.getOptionName(this.resultcombOption.filter((item) =>  this.searchParam.labqueryresult == item.data)) + "; ";
            if(this.searchParam.germflag.length > 0) filtertxt += "细菌标志:" + this.getGermFlagName() + "; ";
            filtertxt += "审核状态:" + (this.searchParam.rechkflag == 1 ? "已审核" : this.searchParam.rechkflag == 2 ? "未审核" : "全部")+ "; ";
            if(this.searchParam.evalcount) filtertxt += "致病菌数:" + this.searchParam.evalcount + "; ";
            return filtertxt;
        },
        getGermFlagName() {
            let flagstr = this.searchParam.germflag.join(",");
            let name = flagstr.replace("1", "阴性结果").replace("2", "阳性菌").replace("3", "正常菌种").replace("4", "涂片结果")
            return name;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if (item.hasOwnProperty("combname")) {
                        optionname += item.combname + ",";
                    } else if (item.hasOwnProperty("label")) {
                        optionname += item.label + ",";
                    } else {
                        optionname += item.display + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        setExportColumn() {
            let allColumnList = [];
            this.$refs.xTable.getTableColumn().tableColumn.forEach(element => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
        btnPrint() {
            var data = this.$refs.xTable.getTableData().fullData;
            if (data.length > 0) {
                const rload = this.$pub.openLoading(this, "正在打印，请稍候……");
                let column = this.$refs.xTable.getTableColumn().tableColumn;
                let str = JSON.stringify(this.$pub.InitColumn(column));
                str += "\r";
                str += JSON.stringify(data);
                let sql = btoa(encodeURIComponent(str));
                jsObj.PrintCustomJsonReport(this.culturerptstyle, sql, this.userno, "细菌结果清单样式", "");
                rload.close();
            } else {
                this.$alert("没有需要打印的数据！");
            }
        },
        RptStyleSetting() {
            var data = this.$refs.xTable.getTableData().fullData;
            if (data.length > 0) {
                const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                let column = this.$refs.xTable.getTableColumn().tableColumn;
                let str = JSON.stringify(this.$pub.InitColumn(column));
                str += "\r";
                str += JSON.stringify(data);
                let sql = btoa(encodeURIComponent(str));
                jsObj.SetCustomJsonPrintConfig(this.culturerptstyle, sql, this.userno, "细菌结果清单样式");
                rload.close();
            } else {
                this.$alert("请选中要打印的数据！");
            }
        },
        querySearchpurpose(str, cb) {
            cb(this.purposeList);
        },
        purposeChange(e) {
            this.searchParam.req_reason = e.purposename;
        },
        // purposeChange(code, name) {
        //     this.searchParam.req_reason = name;
        // },
        querySearchgermcomment(str, cb) {
            cb(this.germcommentList);
        },
        germcommentChange(e) {
            this.searchParam.germcommentname = e.germcommentname;
        },
        inputChange(e, dataname) {
            this.searchParam[dataname] = e;
            this.$forceUpdate();
        },
        openMultiplepop(popdatatype) {
            this.popdatatype = popdatatype;
            this.popcommonVisible = true;
        },
        popchange(c, v, row) {
            let selectdata = [];
            let selectdataname = [];
            if (c.length > 0) {
                c.forEach(element => {
                    selectdata.push(element.hidkey);
                    selectdataname.push(element.hidname);
                });
            }
            console.log(c, this.popdatatype, selectdata)
            this.searchParam[this.popdatatype] = selectdata.join(",");
            this[this.popdatatype + "name"] = selectdataname.join(",");
            this.popcommonVisible = false;
            // if (colcode == "specimen_code") this.queryDcspecimencomm();
        },
        //弹出框关闭时自动保存
        // popcommonClose(keytype) {
        //     var typecol = this.popdatatype;
        //     if (this.$refs[typecol]) {
        //         this.$refs[typecol].select();
        //     }
        // },
        //双击弹窗添加项目
        addrptitem(c, v) {
            console.log(c, v)
            this.searchParam.rptitemval = c;
            this.rptitemname = v;
            // this.searchParam.rpt_itemname = rename;
            this.dialogRptVisible = false;
        },
        selectRptItems(rows) {
            console.log(rows)
            let rpt_item = [];
            let rpt_itemname = [];
            if (rows.length > 0) {
                rows.forEach(element => {
                    rpt_item.push(element.rpt_itemcode);
                    rpt_itemname.push(element.rpt_itemname);
                });
            }
            this.searchParam.rptitemval = rpt_item.join(",");
            this.rptitemname = rpt_itemname.join(",");
            this.dialogRptVisible = false;
        },
        labqueryresultChange() {
            if (this.condtype == 1) {
                this.resultcondData = [];
            } else if (this.condtype == 2) {
                this.medcondData = [];
            }
        },
        conditionPop(type) {
            this.condtype = type;
            if (type == 1) {
                this.fcondData = XEUtils.clone(this.resultcondData, true);
            } else if (type == 2) {
                this.fcondData = XEUtils.clone(this.medcondData, true);
            }
            this.customcondVisible = true;
        },
        refreshLaboption(type, condata) { // 自定义条件新增之后重新查询下拉框数据
            this.customcondVisible = false;
            if (type == 1) this.getLabquery();
            if (type == 2) { // 处理为另存为的数据，下拉框选项和自定义数据分开存放，只记录一个
                if (this.condtype == 1) {
                    this.searchParam.labqueryresult = "";
                    this.resultcondData = condata;
                } else if (this.condtype == 2) {
                    this.searchParam.labqueryresultmed = "";
                    this.medcondData = condata;
                }
            }

        },
        getLabquery() {
            this.$tool.request({
                url: "LIS/LIS4/LIS445",
                method: "post",
                data: {
                    action: "getlabquery",
                    condtype: this.condtype,
                }
            })
            .then(response => {
                if (this.condtype == 1) {
                    this.resultcombOption = response.combOption;
                } else if (this.condtype == 2) {
                    this.medcombOption = response.combOption;
                }
            })
            .catch(e => {
                if (this.condtype == 1) {
                    this.resultcombOption = [];
                } else if (this.condtype == 2) {
                    this.medcombOption = [];
                }
            }); 
        },
        filterDcspecimencomm(queryString, cb) {
            // 调用 callback 返回建议列表的数据
            cb(this.dcspecimencommList);
        },
        changeDcspecimencomm(e) {
            this.searchParam.specimen_comm = e.comm_name;
        },

        currentChangeEvent({ row }) {
            this.queryMed(row.reportid, row.rpt_itemcode);
        },
        footerCellClassName({ $rowIndex, column, columnIndex }) {
            // if (columnIndex === 0) {
            return "col-grey";
            // }
        },
        footerMethod({ columns, data }) {
            return [
                columns.map((column, columnIndex) => {
                    if (columnIndex === 1) {
                        return data.length;
                    }
                    return null;
                }),
            ];
        },
        rowClassName({ row, rowIndex }) {
            if (row.rechk_dt) {
                return "rechkback";
            }
        },
        ResultClassGerm(row) {
            return pubMedresult.ResultClassGerm(this, row);
        },
    }

}
</script>

<style lang="scss" scoped>
.pagetop {
    border: solid 1px #ccc;
    height: 210px;
    overflow-x: auto;
    overflow-x: overlay;
    &::-webkit-scrollbar {
        width: 0px;
        height: 5px;
        border: 4px solid white;
    }
    &::-webkit-scrollbar-thumb {
        background-color: #c1c1c1;
    }
    &::-webkit-scrollbar-track {
        background-color: #f1f1f1;
    }
    /* Buttons */
    &::-webkit-scrollbar-button:single-button {
        background-color: #bbbbbb;
        display: block;
        border-style: solid;
        height: 5px;
        width: 5px;
    }
    /* Left */
    &::-webkit-scrollbar-button:horizontal:decrement {
        margin-right: 2px;
        border-width: 4px 4px 4px 0;
        border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
        background-color: #000000;
    }
    &::-webkit-scrollbar-button:horizontal:decrement:hover {
        border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
    }
    /* Right */
    &::-webkit-scrollbar-button:horizontal:increment {
        margin-left: 2px;
        border-width: 4px 0 4px 4px;
        border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
        background-color: #000000;
    }
    &::-webkit-scrollbar-button:horizontal:increment:hover {
        border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
    }
    // .top-content {
    //     min-width: 1000px;
    // }
    .row-content {
        // display: block;
        width: 100%;
        font-size: 12px;
        margin-top: 3px;
    }
    .row-title {
        margin: 0 5px;
        display: inline-block;
        width: 48px;
        text-align: right;
    }
    .first-title {
        width: 60px;
    }
    .search-param__text {
        display: inline-block;;
    }
    ::v-deep .search-param__text .el-input--mini .el-input__inner {
        height: 26px;
        line-height: 26px;
    }
    ::v-deep .top-datepicker .el-input__inner {
        padding-left: 15px;
        padding-right: 15px;
    }
    ::v-deep .top-datepicker .el-input__prefix {
        left: 2px;
    }
    ::v-deep .top-datepicker .el-input__icon {
        width: 12px;
    }
    .search-time {
        display: inline-block;
    }
    ::v-deep .search-time input {
        width: 100% !important;
        padding: 0 !important;
        text-align: right !important;
    }
    ::v-deep .search-time .el-select .el-input .el-select__caret {
        font-size: 0 !important;
        width: 0 !important;
    }
    ::v-deep .radio-content .el-radio {
        margin-right: 5px !important;
    }
    ::v-deep .search-param__text .el-checkbox {
        margin-right: 10px !important;
    }
    ::v-deep .search-param__text .el-checkbox__label {
        padding-left: 3px !important;
    }
    .search-button {
        margin: 0 2px;
    }
    .top-deal {
        margin: 0px 5px 5px;
        text-align: right;
    }
}
.pagecenter {
    margin-top: 5px;
    overflow: auto;
    width: 100%;
    height: calc(100% - 220px);
    .middle-left {
        .vxe-table {
            height: 100%;
        }
        ::v-deep .rechkback {
            background-color: #c0ffc0 !important;
        }
        ::v-deep .vxe-table.show--foot.scroll--x .vxe-table--body-wrapper {
            height: calc(100% - 55px) !important;
        }
        // ::v-deep .vxe-table--footer-wrapper.body--wrapper {
        //     margin-top: 0 !important;
        // }

    }
}
</style>